<?php
/**
 * Created by PhpStorm.
 * User: Wei
 * Date: 17/10/5
 * Time: 15:20
 */
//由于 json_encode 和 json_decode只支持utf-8编码的字符，GBK的字符要用json就得转换一下
/*
    字符串GBK转码为UTF-8，数字转换为数字。
*/
namespace cn\legendfamily\util{
    function ct2($s)
    {
        if (is_numeric($s)) {
            return intval($s);
        } else {
            return iconv("GBK", "UTF-8", $s);
        }
    }

    /*
        批量处理gbk->utf-8
    */
    function icon_to_utf8($s)
    {
        if (is_array($s)) {
            foreach ($s as $key => $val) {
                $s[$key] = icon_to_utf8($val);
            }
        } else {
            $s = ct2($s);
        }
        return $s;
    }
}

